package com.waterworld.watch.home.manager;

import android.content.Context;
import android.util.Log;

import com.waterworld.watch.common.application.MyApplication;
import com.waterworld.watch.common.bean.BindWatchBean;
import com.waterworld.watch.common.bean.BindWatchUserBean;
import com.waterworld.watch.common.bean.ImeiBean;
import com.waterworld.watch.common.bean.UserInfoBean;
import com.waterworld.watch.common.bean.WatchUserInfoBean;
import com.waterworld.watch.common.dao.LoginDao;
import com.waterworld.watch.common.net.BaseObserverListener;
import com.waterworld.watch.common.net.BaseResultBean;
import com.waterworld.watch.common.net.NetManager;
import com.waterworld.watch.home.bean.RoleBean;
import com.waterworld.watch.home.interfaces.IHomeManager;
import com.waterworld.watch.login.manager.LoginManager;

import rx.Subscriber;

/**
 * Created by nhuan
 * Time:2019/1/17.
 */

public class HomeManager implements IHomeManager {

    private static HomeManager mInstance;
    private Context mContext;

    public static HomeManager getInstance(){
        if(mInstance == null){
            synchronized (HomeManager.class){
                if(mInstance == null){
                    mInstance = new HomeManager(MyApplication.getContext());
                }
            }
        }
        return mInstance;
    }

    private HomeManager(Context context){
        super();
        this.mContext = context;
    }

    /**
     * 检查imei
     * @param imei
     * @param baseObserverListener
     */
    @Override
    public void checkImei(String imei, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().checkImei(imei, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void switchWatch(Integer watchId, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().switchWatch(watchId, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    /**
     * 绑定手表
     * @param imei 设备IMEI号
     * @param baseObserverListener
     */
    @Override
    public void bindWatch(String imei, String relationWithBaby,String head,String name,Integer sex,String birthday,String grade,String classes,String height,String weight, String phone,BaseObserverListener baseObserverListener) {
        NetManager.getInstance().bindWatch(imei, relationWithBaby,head,name,sex,birthday,grade,classes,height,weight,phone, new Subscriber<BaseResultBean<RoleBean>>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean<RoleBean> baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    /**
     * 解绑手表
     * @param unbundlingUserId
     * @param baseObserverListener
     */
    @Override
    public void unbindWatch(Integer unbundlingUserId, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().unbindWatch(unbundlingUserId, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    /**
     * 恢复出厂设置
     * @param baseObserverListener
     */
    @Override
    public void resumeFactory(BaseObserverListener baseObserverListener) {
        NetManager.getInstance().resumeFactory(new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    /**
     * 编辑主页功能区
     * @param functionSigns 功能标识集。
     * @param baseObserverListener
     */
    @Override
    public void editHomePageFunction(String functionSigns, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().editHomePagerFunction(functionSigns, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    /**
     * 获取所有功能
     * @param baseObserverListener
     */
    @Override
    public void getAllFunction(final BaseObserverListener baseObserverListener) {
        NetManager.getInstance().getAllFunction(new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    /**
     * 获取未开启的功能
     * @param baseObserverListener
     */
    @Override
    public void getNotUseFunction(final BaseObserverListener baseObserverListener) {
        NetManager.getInstance().getNotUseFunction(new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    /**
     * 获取用户绑定手表列表
     */
    @Override
    public void listBindWatch(BaseObserverListener baseObserverListener) {
        NetManager.getInstance().listBindWatch(new Subscriber<BaseResultBean<BindWatchBean[]>>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean<BindWatchBean[]> baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    /**
     * 获取手表用户当前信息
     * @param baseObserverListener
     */
    @Override
    public void getCurrentWatchUserInfo(BaseObserverListener baseObserverListener) {
        NetManager.getInstance().getCurrentWatchUserInfo(new Subscriber<BaseResultBean<WatchUserInfoBean>>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean<WatchUserInfoBean> baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    /**
     * 移交管理权限
     * @param authorizeeUserId
     * @param baseObserverListener
     */
    @Override
    public void transferAuthority(Integer authorizeeUserId, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().transferAuthority(authorizeeUserId, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    /**
     * 获取绑定该手表的用户列表
     * @param baseObserverListener
     */
    @Override
    public void listBindWatchUser(BaseObserverListener baseObserverListener) {
        NetManager.getInstance().listBindWatchUser(new Subscriber<BaseResultBean<BindWatchUserBean[]>>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean<BindWatchUserBean[]> baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    /**
     * 获取当前用户信息
     * @param baseObserverListener
     */
    @Override
    public void getCurrentUser(BaseObserverListener baseObserverListener) {
        NetManager.getInstance().getCurrentUser(new Subscriber<BaseResultBean<UserInfoBean>>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean<UserInfoBean> baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    /**
     * 保存手表用户信息
     * @param head
     * @param name
     * @param sex
     * @param birthday
     * @param grade
     * @param classes
     * @param height
     * @param weight
     * @param phone
     * @param baseObserverListener
     */
    @Override
    public void saveWatchUserInfo(String head, String name, Integer sex, String birthday, String grade, String classes, String height, String weight, String phone, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().saveWatchUserInfo(head, name, sex, birthday, grade, classes, height, weight, phone, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    /**
     * 获取通讯录
     * @param baseObserverListener
     */
    @Override
    public void listAddressBook(BaseObserverListener baseObserverListener) {
        NetManager.getInstance().listAddressBook(new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    /**
     * 更新通讯录
     * @param addressBook
     * @param baseObserverListener
     */
    @Override
    public void uploadAddressBook(String addressBook, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().uploadAddressBook(addressBook, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    /**
     * 获取课程表
     * @param baseObserverListener
     */
    @Override
    public void getCourse(BaseObserverListener baseObserverListener) {
        NetManager.getInstance().getCourse(new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    /**
     * 上传课程表
     * @param course
     * @param baseObserverListener
     */
    @Override
    public void uploadCourse(String course, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().uploadCourse(course, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void getLastSportsCount(BaseObserverListener baseObserverListener) {
        NetManager.getInstance().getLastSportsCount(new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void getSportsCount(BaseObserverListener baseObserverListener) {
        NetManager.getInstance().getSportsCount(new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }


    @Override
    public void remotePhoto(BaseObserverListener baseObserverListener) {
        NetManager.getInstance().remotePhoto(new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void listPhoto(Integer pageNum, Integer pageSize, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().listPhoto(pageNum, pageSize, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void deletePhoto(String ids, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().deletePhoto(ids, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void oneWayListening(BaseObserverListener baseObserverListener) {
        NetManager.getInstance().oneWayListening(new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void listSchedule(Integer pageNum, Integer pageSize, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().listSchedule(pageNum, pageSize, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void addSchedule(String remindTime, Integer remindType, String remindDays, String remindContent, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().addSchedule(remindTime, remindType, remindDays, remindContent, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void updateSchedule(Integer id, String remindTime, Integer remindType, String remindDays, String remindContent, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().updateSchedule(id, remindTime, remindType, remindDays, remindContent, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void isEnableSchedule(Integer id, Boolean isEnable, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().isEnableSchedule(id, isEnable, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void deleteSchedule(Integer id, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().deleteSchedule(id, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void listOneWayListeningUser(BaseObserverListener baseObserverListener) {
        NetManager.getInstance().listOneWayListeningUser(new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }
}
